import com.dmotiko.general.*
import mx.utils.Delegate

class WebSiteNavBar 
extends BaseClip {
	
	private var mcLastChild:BaseClip;
	private var mcActiveBtn:BaseClip;
	private var mapBtns:Array;
	private var btnLinkage:String;
	private var sepLinkage:String;
	
	private var nLoaded:Number;
	private var mcContainer:MovieClip;
	
	private function WebSiteNavBar(btnLinkage:String, sepLinkage:String){
		super();
		this.btnLinkage = btnLinkage;
		this.sepLinkage = sepLinkage;
					
	}
	
	private function refreshData():Void {
		this.nLoaded = 0;
		mapBtns = new Array();
		mcContainer = this.createEmptyMovieClip( "mcContainer", mcContainer ? mcContainer.getDepth() : this.getNextHighestDepth() );
		
		for(var i:Number = 0; i < data.length; i++){
			var btn:MovieClip = mcContainer.attachMovie(btnLinkage, "mcBtn" + i, mcContainer.getNextHighestDepth());
			if(i < data.length - 1 && sepLinkage){
				var sep:MovieClip = mcContainer.attachMovie(sepLinkage, "mcSep"+i, mcContainer.getNextHighestDepth());
				btn.separator = sep;
			}
			btn.addEventListener( BaseClipEvent.READY, Delegate.create(this, childReady) );
			mapBtns.push( [ btn, data[i] ]);
		}
	}
	
	public function childReady(evnt){
		var child:BaseClip = evnt.target;
		for(var i:Number = 0; i < mapBtns.length; i++){
			if(mapBtns[i][0] == child){
				child.setData(mapBtns[i][1]);
				child.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, childChanged));
			}
		}
		nLoaded++;
		if(nLoaded == mapBtns.length){
			this.layoutButtons();
		}
	}
	
	private function childChanged(evnt) {
		this.setActiveBtn(evnt.target);
		
	}
	
	public function getActiveBtn():BaseClip {
		return this.mcActiveBtn;
	}
	public function setActiveBtn(value:BaseClip):Void {
		this.mcActiveBtn = value;
	}
	
	/**
	 * @author= sminutoli
	 * @usage= for override porpouses
	 */
	
	private function layoutButtons() {
		return;
	}
	
}